package InternetCode.Socket.Exa6_2;


import java.net.*;

/**
 * 获取远程连接套接字的ip和端口号
 */
public class ServerSocketFrame{
    // 声明ServerSocket对象
    private ServerSocket server;
    // 声明Socket对象socket
    private Socket socket;

    public void getServer() {
        try {
            // 实例化Socket对象
            server = new ServerSocket(1978);
            // 输出信息
            System.out.println("服务器套接字已经创建成功\n");
            while (true) {
                // 输出信息
                System.out.println("等待客户机的连接......\n");
                // 等待连接
                socket = server.accept();
                System.out.println("连接成功......\n");
                System.out.println("连接的客户端ip为："+socket.getInetAddress().getHostAddress());
                System.out.println("连接的客户端的端口号为: "+socket.getPort());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ServerSocketFrame frame = new ServerSocketFrame();
        frame.getServer();
    }


}